// author by welong
// zuowl@qq.com
// 2014-09-05  15:10
// PAT basic 1014

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char week[7][5] = {"MON ", "TUE ", "WED ", "THU ", "FRI ", "SAT ", "SUN "};

void itoasc(int i, char *str, int mark)
{
	if(i < 10)
	{
		str[0] = '0';
		str[1] = '0' + i;
	}
	else
	{
		str[1] = i % 10 + '0';
		i /= 10;
		str[0] = i + '0';
	}

	if(mark)
	{
		str[2] = ':';
		str[3] = 0;
	}
	else
		str[2] = 0;
}

int main(int argc, char **argv)
{
	int  i, j, pos;
	char temp, minute[4];

	char input[4][61], output[30] = {0};

	for(i = 0; i < 4; i++)
		scanf("%s", input[i]);

	for(i=0, j=0; input[0][i] != 0 && input [1][i] != 0; i++)
	{
		if(input[0][i] == input[1][i])
		{
			temp = input[0][i];

			if(temp >= 'A' && temp <='G' && j==0)
			{
				strcat(output, week[temp-'A']);
				j++;
				continue;
			}
			if( ((temp>='0' && temp<='9') || (temp>='A' && temp<='N')) && j==1 )
			{
				if(temp >= '0' && temp <= '9')
					itoasc(temp - '0', minute, 1);
				else
					itoasc(temp - ('A'-10), minute, 1);

				strcat(output, minute);
				break;
			}
		}
	}

	for(i = 0; input[2][i] != 0 && input [3][i] != 0; i++)
	{
		if((input[2][i]==input[3][i]))
		{
			temp = input[2][i];

			if((temp>='a' && temp<='z') || (temp<='Z'&&temp>='A'))
			{
				pos = i;
				itoasc(i, minute, 0);
				strcat(output, minute);
				break;
			}
		}
	}

	printf("%s\n", output);
	return 0;
}